﻿using System;
using System.IO;
using System.Windows.Input;
using LEShortcut.Dialogs.Xaml;
using LEShortcut.Helper;
using LEShortcut.Models;

namespace LEShortcut.Commands
{
    public class SaveConfigCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            var config = parameter as AppConfig;
            if (config != null)
            {
                ConfigHelper.SaveConfig(config, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.js"));
                new SaveConfigCompletedDiaglog().ShowDialog();
            }
            else new SaveConfigFailedDialog().ShowDialog();
        }

        public event EventHandler CanExecuteChanged;
    }
}